﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Update_RoomCategory : System.Web.UI.Page
{
    string i = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            TextBox1.ReadOnly = true;
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql = "select HM_RName,HM_RArea,HM_RBedNum,HM_RPrice,HM_RAirCondition,HM_RTV from HM_RoomCategory where HM_RCategoryId='" + TextBox1.Text.Trim() + "'";
            SqlCommand cmd = new SqlCommand(sql, sqlhelper.conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                RName.Text = sdr["HM_RName"].ToString();
                RArea.Text = sdr["HM_RArea"].ToString();
                RBedNum.Text = sdr["HM_RBedNum"].ToString();
                RPrice.Text = sdr["HM_RPrice"].ToString();
                RAirCondition.Text = sdr["HM_RAirCondition"].ToString();
                RTV.Text = sdr["HM_RTV"].ToString();
            }
            sdr.Close();
        }
        catch
        {
            Response.Write("<script>alert('显示出错，请查看相应代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            sqlhelper.conn.Open();
            string sql1 = string.Format("update HM_RoomCategory set HM_RName='{0}',HM_RArea={1},HM_RBedNum={2},HM_RPrice={3},HM_RAirCondition={4},HM_RTV={5} where HM_RCategoryId={6}", RName.Text, RArea.Text, RBedNum.Text, RPrice.Text, RAirCondition.Text, RTV.Text, TextBox1.Text);
            SqlCommand cmd1 = new SqlCommand(sql1, sqlhelper.conn);
            if (cmd1.ExecuteNonQuery() > 0)
            {
                Response.Write("<script>alert('修改成功！')</script>");
            }
        }
        catch
        {
            Response.Write("<script>alert('修改失败，请查看相应代码！')</script>");
        }
        finally
        {
            sqlhelper.conn.Close();
        }
    }
}